import { ref } from 'vue'
import { adapter, request } from '@/request'
import type { RequestWrapper } from '@/core/interfaces/common'
import { logoutByGet } from '@/core/api/user'

export default function logout() {
  const service = adapter<RequestWrapper<any>>(request)
  const loading = ref(false)

  const fetch = () => {
    const { url, method } = logoutByGet()
    loading.value = true

    return service({
      config: {
        url,
        method
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [null, fetch, loading] as const
}
